package com.lpit.service.impl;

import com.lpit.constant.Constant;
import com.lpit.dto.CommentsReplyDto;
import com.lpit.mapper.CommentReplyMapper;
import com.lpit.result.ResponseResult;
import com.lpit.service.CommentsReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author Administrator
 */
@Service
public class CommentsReplyServiceImpl implements CommentsReplyService {
    @Autowired
    private CommentReplyMapper commentReplyMapper;
    /**
     * 对文章的评论添加回复
     * @param commentsReplyDto
     * @return ResponseResult<Integer>
     */
    @Override
    public ResponseResult<Integer> addCommentsReply(CommentsReplyDto commentsReplyDto) {
        if (null == commentsReplyDto.getCommentTime() || "".equals(commentsReplyDto.getCommentTime())) {
            commentsReplyDto.setCommentTime(new SimpleDateFormat(Constant.TIME_FORMAT).format(new Date()));
        }
        if (null == commentsReplyDto.getUserId() || 0 == commentsReplyDto.getUserId()) {
            return new ResponseResult<>(404, null, Constant.THE_USER_WAS_NOT_FOUND);
        }
        if (null == commentsReplyDto.getCommentId() || 0 == commentsReplyDto.getCommentId()) {
            return new ResponseResult<>(404, null, Constant.NO_RELATED_ARTICLE_FOUND);
        }
        Integer integer = commentReplyMapper.addCommentsReply(commentsReplyDto);
        if(null == integer || 0 == integer){
            return new ResponseResult<>(404, null, Constant.MISTAKE);
        }
        return new ResponseResult<>(200, integer, Constant.SUCCESS);
    }
}
